#include<func.h>
//同一个线程对同一把锁加锁两次会造成死锁，设置为检错锁就可以在第二次加锁时显示
int main()
{
    pthread_mutexattr_t mutex_attr;//定义一个锁属性
    pthread_mutexattr_init(&mutex_attr);//初始化锁属性
    pthread_mutexattr_settype(&mutex_attr,PTHREAD_MUTEX_ERRORCHECK);//设置为检错锁
    pthread_mutex_t mutex;
    int ret=pthread_mutex_init(&mutex,&mutex_attr);//初始化锁,第二个参数是锁属性
    THREAD_ERR_CHECK(ret,"pthread_mutex_init")
    ret=pthread_mutex_lock(&mutex);//加锁一次
    THREAD_ERR_CHECK(ret,"pthread_mutex_lock");
    printf("lock once success\n");
    ret=pthread_mutex_lock(&mutex);//第二次加锁时会被检测
    THREAD_ERR_CHECK(ret,"pthread_mutex_lock");
    printf("lock twice success\n");
    return 0;
}